using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Arch.Aspects;
using Arch.Model;

namespace Arch.Samples.Model
{
    [DataContract(IsReference = true)]
    [Order("Title"), Includes("CreationUser, GlobalCategory, SubCategory")]
    [SecurityAccess(ReadAccess = Access.Authentified, WriteRoles = "Admin, User")]
    public partial class Todo : Entity<int>
    {
        [DataMember]
        [   
            Required, 
            StringLength(50), 
            Display(Order = 0),
        ]
        public virtual string Title { get; set; }

        [DataMember]
        [   
            Required, 
            StringLength(1000), 
            Display(AutoGenerateField = false),
        ]
        public virtual string Description { get; set; }

        [DataMember]
        [Increment]
        public virtual int Version { get; set; }

        [DataMember]
        [
            AutoNowCreate,
            Editable(false), 
            DisplayFormat(DataFormatString = "d"),
        ]
        public virtual DateTime CreationDate { get; set; }

        [DataMember]
        [
            AutoNow,
            Editable(false), 
            DisplayFormat(DataFormatString = "d"),
        ]
        public virtual DateTime UpdateDate { get; set; }

        [DataMember]
        [Display(AutoGenerateField = false)]
        public virtual int CreationUserId { get; set; }

        [DataMember]
        [Display(AutoGenerateField = false)]
        public virtual int GlobalCategoryId { get; set; }

        [DataMember]
        [Display(AutoGenerateField = false)]
        public virtual int SubCategoryId { get; set; }

        [DataMember]
        //[AssociationAttribute("Todo_User", "CreationUserId", "Id", IsForeignKey = true)]    
        public virtual User CreationUser { get; set; }

        [DataMember]
        //[AssociationAttribute("Todo_GlobalCategory", "GlobalCategoryId", "Id", IsForeignKey = true)]
        public virtual GlobalCategory GlobalCategory { get; set; }

        [DataMember]
        //[AssociationAttribute("Todo_SubCategory", "SubCategoryId", "Id", IsForeignKey = true)]
        public virtual SubCategory SubCategory { get; set; }

        public override string ToString()
        {
            return Title;
        }
    }
}
